#include "XmlApp.h"
#include <iostream>

namespace conex {
	using namespace std;
	void XmlApp::Go() {
		//new a vocabulary
		Vocabulary voc;
		//new a data access for vocabulary from voc.xml
		cout << "loading vocabulary" << endl;
		VocabularyXmlAccess* xmlAccess = new VocabularyXmlAccess("/data/Vocabulary_en_1.0.1.xml", "XPMVoc_V09R65.xsd");
		cout << "loaded vocabulary" << endl;
		//new a vocabulary control with a special data access
		VocabularyControl vocControl(xmlAccess);
		//use vocabulary to load data to the vocabulary
		vocControl.Load(voc);
		//add a new term to the vocabulary
		TermControl tcontrol(&voc);
		Term* term = tcontrol.CreateTerm();
		tcontrol.SetWord(L"xiao", term);
		//term->CreateStructure()->SetText("xiao");
		tcontrol.SetTextExplanation(L"my name is xiao", term);
		//term->CreateInterpretation()->SetTextExplanation("my name is xiao");
		//add the other new term to the vocabulary
		Term* term2 = voc.CreateTerm();
		tcontrol.SetWord(L"chen", term2);
		//term2->CreateStructure()->SetText("chen");
		tcontrol.SetTextExplanation(L"my brother's name is chen", term2);
		//term2->CreateInterpretation()->SetTextExplanation("my brother's name is chen");
		//get the context of the vocabulary
		//VocabularyContext* vocContext = voc.GetVocabularyContext();
		//get the context of the term
		Context* context = term->context();
		//add a antonym relation from term1 to term2
		context->AddRelation(ANTONYM, term2);
		//delete all the antonyms of term1
		context->DeleteRelations(ANTONYM);
		//add a classifier relation from term1 to term2
		context->AddRelation(CATEGORY, term2);
		//add a synonym relation from term1 to term2
		context->AddRelation(SYNONYM, term2);
		//add a synonym relation from voc to term2
		//vocContext->AddSynonym()->RelatedTo(term2);	
		//save the vocabulary to the harddisk or the database
		vocControl.Save(voc);
		//clear all the terms in the memory
		voc.ClearTerms();
	}

	void XmlApp::In2OutTest() {
		VocabularyControl control(VocabularyControl::XML_SAX2);
		Vocabulary voc;
		control.Load(voc);
		control.Save(voc);
	}
}